import numpy as np

# 产生随机数据
def randomData(n):
    x = np.arange(n)
    y = np.random.randint(-50, 50, size=(n,)) + 50.0 * np.log1p(np.arange(n))
    return [x, y]


import pandas as pd

# 类别特征独热处理
def get_dummies(data):
    columns = data.columns
    # 转为object类型
    for i in range(len(columns)):
        column_name = columns[i]
        column_data = data[column_name]
        column_data.astype("object")
        column_data = pd.get_dummies(column_data, prefix=column_name)
        if i == 0:
            result = column_data
        else:
            result = pd.concat([result, column_data], ignore_index=False, axis=1)
    return result


# 均方误差
from sklearn.metrics import mean_squared_error

# 计算RMSE
def RMSE(y, y_pred):
    return mean_squared_error(y, y_pred) / len(y)

